package com.ourteam.workspace.dao.impl;

import com.ourteam.workspace.dao.IWorkspaceScmLogDAO;
import com.ourteam.workspace.dao.WorkspaceScmLog;
import com.ourteam.workspace.dao.WorkspaceScmLogDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-11-30 18:42:34 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractWorkspaceScmLogDAOJdbcImpl extends AbstractSpringDAO
    implements IWorkspaceScmLogDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        ParentId,
        WorkspaceId,
        WorkspaceScmConfigId,
        Revision,
        Author,
        RevisionTime,
        Comment,
        Status,
        Remarks,
        TotalLines,
        TotalSize,
        WorkspaceName
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.ParentId,
        _DataObjectProperty.WorkspaceId,
        _DataObjectProperty.WorkspaceScmConfigId,
        _DataObjectProperty.Revision,
        _DataObjectProperty.Author,
        _DataObjectProperty.RevisionTime,
        _DataObjectProperty.Comment,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks,
        _DataObjectProperty.TotalLines,
        _DataObjectProperty.TotalSize,
        _DataObjectProperty.WorkspaceName
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<WorkspaceScmLog, WorkspaceScmLogDAOQueryBean> daoHelper;

  public AbstractWorkspaceScmLogDAOJdbcImpl() {
    super();
    daoHelper = new DataAccessObjectHelper<WorkspaceScmLog, WorkspaceScmLogDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.workspace.dao.IWorkspaceDAO.EntityName)
          .append(" WORKSPACE ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.workspace.dao.IWorkspaceDAO.Id,
              com.ourteam.workspace.dao.IWorkspaceDAO.EntityName + ".",
              "WORKSPACE."));
      relatedJoinSQLBuffer.append(" = ").append(WorkspaceId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aWorkspaceScmLog
   * @throws Exception
   */
  public boolean checkIsUnique(WorkspaceScmLog aWorkspaceScmLog) throws Exception {

    if (aWorkspaceScmLog == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aWorkspaceScmLog.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aWorkspaceScmLog
   * @throws Exception
   */
  public void insert(WorkspaceScmLog aWorkspaceScmLog) throws Exception {

    super.doInsert(aWorkspaceScmLog);
  }

  /**
   * Batch Insert Datas
   *
   * @param aWorkspaceScmLog
   * @throws Exception
   */
  public void batchInsert(WorkspaceScmLog[] aWorkspaceScmLogs) throws Exception {

    super.doBatchInsert(aWorkspaceScmLogs);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(WorkspaceScmLogDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(WorkspaceScmLog aWorkspaceScmLog) throws Exception {

    delete(aWorkspaceScmLog.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aWorkspaceScmLog
   * @throws Exception
   */
  public void update(WorkspaceScmLog aWorkspaceScmLog) throws Exception {

    if (aWorkspaceScmLog.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aWorkspaceScmLog);

    WorkspaceScmLog tempObj = findById(aWorkspaceScmLog.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aWorkspaceScmLog, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aWorkspaceScmLogs[]
   * @throws Exception
   */
  public void batchUpdate(WorkspaceScmLog[] aWorkspaceScmLogs) throws Exception {

    super.doBatchUpdate(aWorkspaceScmLogs);
  }

  /**
   * Update Data By Condictions
   *
   * @param aWorkspaceScmLog
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(WorkspaceScmLog aWorkspaceScmLog, WorkspaceScmLogDAOQueryBean aQueryBean)
      throws Exception {

    super.doUpdateByQuery(aWorkspaceScmLog, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(WorkspaceScmLogDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(WorkspaceScmLog aWorkspaceScmLog) throws Exception {

    if (aWorkspaceScmLog.getRevision() == null) {
      throw new Exception("The WorkspaceScmLog.revision value is not allow NULL");
    }

    if (aWorkspaceScmLog.getAuthor() == null) {
      throw new Exception("The WorkspaceScmLog.author value is not allow NULL");
    }

    if (aWorkspaceScmLog.getRevisionTime() == null) {
      throw new Exception("The WorkspaceScmLog.revisionTime value is not allow NULL");
    }

    if (aWorkspaceScmLog.getComment() == null) {
      throw new Exception("The WorkspaceScmLog.comment value is not allow NULL");
    }

    if (aWorkspaceScmLog.getStatus() == null) {
      throw new Exception("The WorkspaceScmLog.status value is not allow NULL");
    }

    if (aWorkspaceScmLog.getRemarks() == null) {
      throw new Exception("The WorkspaceScmLog.remarks value is not allow NULL");
    }

    if (aWorkspaceScmLog.getWorkspaceName() == null) {
      throw new Exception("The WorkspaceScmLog.workspaceName value is not allow NULL");
    }
  }

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public WorkspaceScmLog findById(final long id) throws Exception {

    WorkspaceScmLogDAOQueryBean queryBean = new WorkspaceScmLogDAOQueryBean();

    WorkspaceScmLogDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    WorkspaceScmLog[] WorkspaceScmLogs = query(queryBean);

    if (WorkspaceScmLogs.length == 0) {
      return null;
    } else {
      return WorkspaceScmLogs[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return WorkspaceScmLog[]
   * @throws Exception
   */
  public WorkspaceScmLog[] query(WorkspaceScmLogDAOQueryBean queryBean) throws Exception {

    List result = super.doQuery(queryBean, new JdbcWorkspaceScmLogRowMapper());

    return (WorkspaceScmLog[]) result.toArray(new WorkspaceScmLog[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(WorkspaceScmLogDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(WorkspaceScmLogDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      WorkspaceScmLog[] aWorkspaceScmLogs, WorkspaceScmLogDAOQueryBean queryBean) throws Exception {
    daoHelper.synchronize(aWorkspaceScmLogs, queryBean);
  }

  public void synchronize(
      WorkspaceScmLog[] aWorkspaceScmLogs,
      WorkspaceScmLogDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<WorkspaceScmLog> callBack)
      throws Exception {
    daoHelper.synchronize(aWorkspaceScmLogs, queryBean, callBack);
  }

  private com.ourteam.workspace.dao.impl.AbstractWorkspaceScmChangePathLogDAOJdbcImpl
      WorkspaceScmChangePathLogDao;

  public void setWorkspaceScmChangePathLogDao(
      com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO WorkspaceScmChangePathLogDao) {
    this.WorkspaceScmChangePathLogDao =
        (com.ourteam.workspace.dao.impl.AbstractWorkspaceScmChangePathLogDAOJdbcImpl)
            WorkspaceScmChangePathLogDao;
  }

  /**
   * Query Related WorkspaceScmChangePathLog
   *
   * @param queryBean
   * @throws Exception
   */
  public com.ourteam.workspace.dao.WorkspaceScmChangePathLog[] queryWorkspaceScmChangePathLog(
      WorkspaceScmLogDAOQueryBean queryBean) throws Exception {

    StringBuffer joinSQL = new StringBuffer();

    joinSQL.append(" LEFT JOIN ").append(EntityName).append(" ON ( ");

    joinSQL
        .append(com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.WorkspaceScmLogId)
        .append(" = ")
        .append(Id);

    joinSQL.append(" ) ");

    String entityName =
        com.ourteam.workspace.dao.impl.WorkspaceScmChangePathLogDAO.EntityName
            + " ref_WorkspaceScmChangePathLog";

    String[] entityFields =
        com.ourteam.workspace.dao.impl.WorkspaceScmChangePathLogDAO.ENTITY_FIELDS;

    String[] entityProperties =
        com.ourteam.workspace.dao.impl.WorkspaceScmChangePathLogDAO.ENTITY_PROPERTIES;

    List list =
        WorkspaceScmChangePathLogDao.doQuery(
            entityName,
            entityFields,
            entityProperties,
            queryBean,
            joinSQL.toString(),
            new com.ourteam.workspace.dao.impl.WorkspaceScmChangePathLogDAO
                .JdbcWorkspaceScmChangePathLogRowMapper());

    return (com.ourteam.workspace.dao.WorkspaceScmChangePathLog[])
        list.toArray(new com.ourteam.workspace.dao.WorkspaceScmChangePathLog[list.size()]);
  }

  /**
   * Query Related WorkspaceScmChangePathLog Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] queryWorkspaceScmChangePathLogSelective(
      WorkspaceScmLogDAOQueryBean queryBean) throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {

      queryBean.addSelectProperty(com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.Id, "id");

      queryBean.addSelectProperty(
          com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.WorkspaceScmLogId,
          "workspaceScmLogId");

      queryBean.addSelectProperty(
          com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.Path, "path");

      queryBean.addSelectProperty(
          com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.Action, "action");

      queryBean.addSelectProperty(
          com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.Copysrcrevision,
          "copysrcrevision");

      queryBean.addSelectProperty(
          com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.Copysrcpath, "copysrcpath");

      queryBean.addSelectProperty(
          com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.Status, "status");

      queryBean.addSelectProperty(
          com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.Remarks, "remarks");

      queryBean.addSelectProperty(
          com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.WorkspaceId, "workspaceId");

      queryBean.addSelectProperty(
          com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.WorkspaceScmConfigId,
          "workspaceScmConfigId");

      queryBean.addSelectProperty(
          com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.ChangeLineCount,
          "changeLineCount");

      queryBean.addSelectProperty(
          com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.LineCount, "lineCount");

      queryBean.addSelectProperty(
          com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.CommentLineCount,
          "commentLineCount");

      queryBean.addSelectProperty(
          com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.BlankLineCount, "blankLineCount");

      queryBean.addSelectProperty(
          com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.FileSize, "fileSize");
    }

    StringBuffer joinSQL = new StringBuffer();

    joinSQL.append(" LEFT JOIN ").append(EntityName).append(" ON ( ");

    joinSQL
        .append(com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.WorkspaceScmLogId)
        .append(" = ")
        .append(Id);

    joinSQL.append(" ) ");

    String entityName =
        com.ourteam.workspace.dao.impl.WorkspaceScmChangePathLogDAO.EntityName
            + " ref_WorkspaceScmChangePathLog";

    return WorkspaceScmChangePathLogDao.doQuerySelective(entityName, queryBean, joinSQL.toString());
  }

  /**
   * Update Related WorkspaceScmChangePathLog
   *
   * @param aWorkspaceScmChangePathLog
   * @param aQueryBean
   * @model
   * @throws Exception
   */
  public void updateWorkspaceScmChangePathLog(
      com.ourteam.workspace.dao.WorkspaceScmChangePathLog aWorkspaceScmChangePathLog,
      WorkspaceScmLogDAOQueryBean aQueryBean)
      throws Exception {

    StringBuffer joinSQL = new StringBuffer();

    joinSQL.append(" LEFT JOIN ").append(EntityName).append(" ON ( ");

    joinSQL
        .append(com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.WorkspaceScmLogId)
        .append(" = ")
        .append(Id);

    joinSQL.append(" ) ");

    String entityName =
        com.ourteam.workspace.dao.impl.WorkspaceScmChangePathLogDAO.EntityName
            + " ref_WorkspaceScmChangePathLog";

    String[] entityFields =
        com.ourteam.workspace.dao.impl.WorkspaceScmChangePathLogDAO.ENTITY_FIELDS;

    String[] entityProperties =
        com.ourteam.workspace.dao.impl.WorkspaceScmChangePathLogDAO.ENTITY_PROPERTIES;

    WorkspaceScmChangePathLogDao.doUpdateByQuery(
        entityName,
        entityFields,
        entityProperties,
        joinSQL.toString(),
        aWorkspaceScmChangePathLog,
        aQueryBean);
  }

  /**
   * Delete Related WorkspaceScmChangePathLog
   *
   * @param aQueryBean
   * @model
   * @throws Exception
   */
  public void deleteWorkspaceScmChangePathLog(WorkspaceScmLogDAOQueryBean aQueryBean)
      throws Exception {

    StringBuffer joinSQL = new StringBuffer();

    joinSQL.append(" LEFT JOIN ").append(EntityName).append(" ON ( ");

    joinSQL
        .append(com.ourteam.workspace.dao.IWorkspaceScmChangePathLogDAO.WorkspaceScmLogId)
        .append(" = ")
        .append(Id);

    joinSQL.append(" ) ");

    String entityName =
        com.ourteam.workspace.dao.impl.WorkspaceScmChangePathLogDAO
            .EntityName; // + " ref_WorkspaceScmChangePathLog";

    WorkspaceScmChangePathLogDao.doDeleteByQuery(entityName, joinSQL.toString(), aQueryBean);
  }

  public static class JdbcWorkspaceScmLogRowMapper implements RowMapper<WorkspaceScmLog> {

    public WorkspaceScmLog mapRow(ResultSet resultSet, int arg1) throws SQLException {
      WorkspaceScmLog object = new WorkspaceScmLog();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object parentId = null;

        parentId = resultSet.getObject(columnIndex++);

        object.setParentIdNull(resultSet.getBoolean(columnIndex++));

        if (parentId != null) {

          setBeanValue(object, _DataObjectProperty.ParentId, parentId);
        }

        Object workspaceId = null;

        workspaceId = resultSet.getObject(columnIndex++);

        object.setWorkspaceIdNull(resultSet.getBoolean(columnIndex++));

        if (workspaceId != null) {

          setBeanValue(object, _DataObjectProperty.WorkspaceId, workspaceId);
        }

        Object workspaceScmConfigId = null;

        workspaceScmConfigId = resultSet.getObject(columnIndex++);

        object.setWorkspaceScmConfigIdNull(resultSet.getBoolean(columnIndex++));

        if (workspaceScmConfigId != null) {

          setBeanValue(object, _DataObjectProperty.WorkspaceScmConfigId, workspaceScmConfigId);
        }

        Object revision = null;

        revision = resultSet.getObject(columnIndex++);

        object.setRevisionNull(resultSet.getBoolean(columnIndex++));

        if (revision != null) {

          setBeanValue(object, _DataObjectProperty.Revision, revision);
        }

        Object author = null;

        author = resultSet.getObject(columnIndex++);

        object.setAuthorNull(resultSet.getBoolean(columnIndex++));

        if (author != null) {

          setBeanValue(object, _DataObjectProperty.Author, author);
        }

        Object revisionTime = null;

        __dataType = resultSet.getMetaData().getColumnType(columnIndex);

        if (__dataType == java.sql.Types.DATE
            || __dataType == java.sql.Types.TIME
            || __dataType == java.sql.Types.TIMESTAMP) {
          revisionTime = resultSet.getTimestamp(columnIndex++);

        } else {
          revisionTime = resultSet.getObject(columnIndex++);
        }

        object.setRevisionTimeNull(resultSet.getBoolean(columnIndex++));

        if (revisionTime != null) {

          setBeanValue(object, _DataObjectProperty.RevisionTime, revisionTime);
        }

        Object comment = null;

        comment = resultSet.getObject(columnIndex++);

        object.setCommentNull(resultSet.getBoolean(columnIndex++));

        if (comment != null) {

          setBeanValue(object, _DataObjectProperty.Comment, comment);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        Object totalLines = null;

        totalLines = resultSet.getObject(columnIndex++);

        object.setTotalLinesNull(resultSet.getBoolean(columnIndex++));

        if (totalLines != null) {

          setBeanValue(object, _DataObjectProperty.TotalLines, totalLines);
        }

        Object totalSize = null;

        totalSize = resultSet.getObject(columnIndex++);

        object.setTotalSizeNull(resultSet.getBoolean(columnIndex++));

        if (totalSize != null) {

          setBeanValue(object, _DataObjectProperty.TotalSize, totalSize);
        }

        Object workspaceName = null;

        workspaceName = resultSet.getObject(columnIndex++);

        object.setWorkspaceNameNull(resultSet.getBoolean(columnIndex++));

        if (workspaceName != null) {

          setBeanValue(object, _DataObjectProperty.WorkspaceName, workspaceName);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
